package com.wlyuan.open.scanner.utils.enums.quotation;

import com.wlyuan.utils.BaseEnum;
import com.wlyuan.utils.EnumUtils;

import java.util.Map;
import java.util.Optional;

/**
 * @author lijing
 */
public enum TemplateRelationTypeEnum implements BaseEnum {
    CUSTOMER(1, "发货方合约"), CARRIER(2, "承运方合约");

    private static final Map<Integer, TemplateRelationTypeEnum> MAP = EnumUtils.map(TemplateRelationTypeEnum.values());
    private final int value;
    private final String name;

    TemplateRelationTypeEnum(int value, String name) {
        this.value = value;
        this.name = name;
    }

    @Override
    public String getName() {
        return this.name;
    }

    @Override
    public Integer getValue() {
        return this.value;
    }

    public static TemplateRelationTypeEnum fromValue(Integer value) {
        return Optional.ofNullable(value).map(v -> MAP.get(v)).orElse(null);
    }

    public static boolean isCustomer(Integer val) {
        return CUSTOMER.getValue().equals(val);
    }

    public static boolean isCarrier(Integer val) {
        return CARRIER.getValue().equals(val);
    }
}
